//
//  SAPermissionsHeaderView2.m
//  Saas
//
//  Created by 黄志刚 on 2021/1/19.
//  Copyright © 2021 bing. All rights reserved.
//

#import "SAPermissionsHeaderView2.h"
#import "SAPermissionsModel.h"

@interface SAPermissionsHeaderView2 ()

@property (nonatomic, strong) UIButton *templateBtn;
@property (nonatomic, strong) UIView *line;

@end

@implementation SAPermissionsHeaderView2

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAPermsMenuListModel *)model {
    _model = model;
    _templateBtn.selected = [model.isDelete isEqualToString:@"0"];
    [_templateBtn setTitle:[NSString stringWithFormat:@" %@",model.menuName] forState:UIControlStateNormal];
}

#pragma mark - event
-(void)clickedTemplateBtn:(UIButton *)sender {
    sender.selected = !sender.isSelected;
    if (sender.isSelected == YES) {
        self.model.isDelete = @"0";
    }else {
        self.model.isDelete = @"1";
    }
    !self.updateStatusBlock ?: self.updateStatusBlock();
}

-(void)initUI {
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.templateBtn];
    [self.contentView addSubview:self.line];
}

-(UIButton *)templateBtn {
    if (!_templateBtn) {
        _templateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _templateBtn.frame = CGRectMake(kScaleNum(20), 0, kScaleNum(110), kScaleNum(45));
        [_templateBtn setImage:[UIImage imageNamed:@"StaffManager_rect"] forState:UIControlStateNormal];
        [_templateBtn setImage:[UIImage imageNamed:@"StaffManager_rect2"] forState:UIControlStateSelected];
        _templateBtn.titleLabel.font = kBFont(16);
        [_templateBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        _templateBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [_templateBtn addTarget:self action:@selector(clickedTemplateBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _templateBtn;
}

-(UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, kScaleNum(44), kScreenWidth, kScaleNum(1))];
        _line.backgroundColor = kLineColor;
    }
    return _line;
}

@end

